from config.all_paths import config_variable_path
from notify.send_feishu_DS import parse_prometheus_data, generate_message_content_GZF, push_message, \
    generate_message_content_SIP, generate_message_content_XCXSIP, generate_message_content_JZKB, \
    generate_message_content_JZ, generate_message_content_FG, generate_message_content_YSDS, \
    generate_message_content_CZKB, generate_message_content_YSDS_1, generate_message_content_AiRobot, \
    generate_message_content_AiRobot_1, generate_message_content_AI_XIAOWU
from utils.file_handling.ini_handling import LoadIni
from utils.others_tool.other_tool import get_opt
import sys
from utils.jenkins_tool.operation_jenkins import OperationJenkins


def main():
    # 获取命令行参数
    t_opt = get_opt(sys.argv[1:])
    jobname = t_opt.get('job')
    push_type = t_opt.get('type')
    push_template = t_opt.get('template')  # 推送的模板

    # 获取推送的webhook地址
    webhook_test = LoadIni("notify_variable.ini").getSection('feishu').get('webhook_test')
    webhook_pro = LoadIni("notify_variable.ini").getSection('feishu').get('webhook_pro')
    webhook_yw = LoadIni("notify_variable.ini").getSection('feishu').get('webhook_yw')

    # 获取jenkins配置
    jenkins_config = LoadIni("jenkins.ini").getSection('jenkins')

    # 构造推送的报告，并推送
    content = parse_prometheus_data(config_variable_path)
    description = OperationJenkins(jobname, jenkins_config).get_job_description()
    report_url = OperationJenkins(jobname, jenkins_config).get_report_url()
    ai_report_url = OperationJenkins(jobname, jenkins_config).get_ai_report() + 'ai_report.xlsx'

    message_content = ''
    message_content1 = ''
    if push_template == 'GZF':
        message_content = generate_message_content_GZF(content, description,report_url)
    elif push_template == 'SIP':
        message_content = generate_message_content_SIP(content, description, report_url)
    elif push_template == 'XCXSIP':
        message_content = generate_message_content_XCXSIP(content, description, report_url)
    elif push_template == 'JZ':
        message_content = generate_message_content_JZ(content, description, report_url)
    elif push_template == 'FG':
        message_content = generate_message_content_FG(content, description, report_url)
    elif push_template == 'JZKB':
        message_content = generate_message_content_JZKB(content, description, report_url)
    elif push_template == 'CZKB':
        message_content = generate_message_content_CZKB(content, description, report_url)
    elif push_template == 'YSDS':
        message_content = generate_message_content_YSDS(content, description, report_url)
    elif push_template == 'YSDS1':
        message_content = generate_message_content_YSDS_1(content, description, report_url)
    # elif push_template == 'AI':
    #     message_content = generate_message_content_AiRobot(content, description, report_url)
    #     message_content1 = generate_message_content_AiRobot_1(content, description, report_url)
    elif push_template == 'AIXW':
        message_content = generate_message_content_AI_XIAOWU(content, description, report_url, ai_report_url)
    else:
        print("请输入正确的推送模板参数")

    if push_type == 'test':
        push_message(webhook_test, message_content)
    elif push_type == 'pro':
        push_message(webhook_pro, message_content)
    elif push_type == 'yw':
        push_message(webhook_yw, message_content)
    # elif push_type == 'AI':
    #     push_message(webhook_yw, message_content)
    #     push_message(webhook_yw, message_content1)
    else:
        print("请输入正确的推送环境参数")



if __name__ == '__main__':
    main()
    # python run_send_message.py --type=test --job=jenkins_jobname --template=SIP
